package com.ss.android.article.base.feature.video;

import com.bytedance.common.utility.aa;
import com.ss.android.article.base.feature.app.a.ArticleConstants;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;

public class VideoUrlDepend {
    public VideoUrlDepend() {

    }

    public static HashMap commonParamsWithIP() {
        return null;
    }

    private static String getBytedangcePlayUrl(String arg7) {
        HashMap v2 = new HashMap();
        v2.put("version", "1");
        v2.put("user", "toutiao");
        v2.put("video", arg7);
        v2.put("vtype", "mp4");
        String v3 = String.valueOf(new Date().getTime() / 1000);
        v2.put("ts", v3);
        TreeSet v0 = new TreeSet(v2.keySet());
        StringBuilder v4 = new StringBuilder();
        Iterator v5 = ((SortedSet)v0).iterator();
        while(v5.hasNext()) {
            Object v0_1 = v5.next();
            Object v1 = v2.get(v0_1);
            v4.append(((String)v0_1));
            v4.append(((String)v1));
        }

        v4.append("17601e2231500d8c3389dd5d6afd08de");
        String v0_2 = aa.md5(v4.toString());
        ArrayList v1_1 = new ArrayList();
        v1_1.add("1");
        v1_1.add("toutiao");
        v1_1.add(v3);
        v1_1.add(v0_2);
        v1_1.add("mp4");
        v1_1.add(arg7);
        v4.delete(0, v4.length());
        v4.append(ArticleConstants.videoPlayUrl);
        Iterator v1_2 = v1_1.iterator();
        while(v1_2.hasNext()) {
            v4.append(v1_2.next());
            v4.append("/");
        }

        return v4.substring(0, v4.length() - 1);
    }

    private static String getLetvPlayUrl(String arg9) {
        Object v0_1;
        HashMap v2 = new HashMap();
        v2.put("user", "ff03bba36a");
        v2.put("video", arg9);
        v2.put("vtype", "mp4");
        v2.put("ts", String.valueOf(new Date().getTime() / 1000));
        TreeSet v0 = new TreeSet(v2.keySet());
        StringBuilder v3 = new StringBuilder();
        Iterator v4 = ((SortedSet)v0).iterator();
        while(v4.hasNext()) {
            v0_1 = v4.next();
            Object v1 = v2.get(v0_1);
            v3.append(((String)v0_1));
            v3.append(((String)v1));
        }

        v3.append("944fdf087f83a1f6b7aad88ec2793bbc");
        v2.put("sign", aa.md5(v3.toString()));
        Set v0_2 = v2.entrySet();
        v3.delete(0, v3.length());
        v3.append("http://api.letvcloud.com/getplayurl.php");
        v3.append("?");
        Iterator v2_1 = v0_2.iterator();
        while(v2_1.hasNext()) {
            v0_1 = v2_1.next();
            v3.append(((Map.Entry)v0_1).getKey());
            v3.append("=");
            v3.append(((Map.Entry)v0_1).getValue());
            v3.append("&");
        }

        return v3.substring(0, v3.length() - 1);
    }

    public static String urlWithVideoId(int arg4, String arg5, long arg6, String arg8, int arg9, long arg10) {
        long v2 = 0;
        String v0 = "";
        switch(arg4) {
            case 0: {
                v0 = VideoUrlDepend.getBytedangcePlayUrl(arg5);
                if(android.support.design.a.isTextEmpty(v0)) {
                    return v0;
                }

                StringBuilder v1 = new StringBuilder();
                v1.append(v0);
                v1.append("?");
                if(arg9 > 0) {
                    v1.append("play_type");
                    v1.append("=");
                    v1.append(String.valueOf(arg9));
                }

                if(arg6 > v2) {
                    v1.append("&");
                    v1.append("item_id");
                    v1.append("=");
                    v1.append(String.valueOf(arg6));
                }

                if(!android.support.design.a.isTextEmpty(arg8)) {
                    v1.append("&");
                    v1.append("category");
                    v1.append("=");
                    v1.append(arg8);
                }

                if(arg10 > v2) {
                    v1.append("&");
                    v1.append("ad_id");
                    v1.append("=");
                    v1.append(String.valueOf(arg10));
                }

                v0 = v1.toString();
                break;
            }
            case 1: {
                v0 = VideoUrlDepend.getLetvPlayUrl(arg5);
                break;
            }
        }

        return v0;
    }
}

